/*******************************************************************************
 * Copyright 2011 Google Inc. All Rights Reserved.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package net.m2m.apbnm.patientregistration.client;

import java.util.ArrayList;
import java.util.List;



import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.AbsolutePanel;




import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.StackLayoutPanel;
import com.google.gwt.user.client.ui.TabLayoutPanel;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.cellview.client.CellTree;
import com.google.gwt.view.client.TreeViewModel;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.TreeViewModel.NodeInfo;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.cellview.client.TreeNode;
import com.google.gwt.view.client.SingleSelectionModel;
import com.google.gwt.view.client.AbstractDataProvider;
import com.google.gwt.view.client.SelectionModel.AbstractSelectionModel;
import com.google.gwt.view.client.NoSelectionModel;
import com.google.gwt.view.client.TreeViewModel.DefaultNodeInfo;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.DockLayoutPanel;




import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.TabLayoutPanel;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SingleSelectionModel;
import com.google.gwt.view.client.TreeViewModel;
import com.google.gwt.view.client.TreeViewModel.DefaultNodeInfo;
import com.google.gwt.view.client.TreeViewModel.NodeInfo;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class AddPatient implements EntryPoint {
	///////////
	private static class Playlist {
	    private final String name;
	    private final List<String> songs = new ArrayList<String>();

	    public Playlist(String name) {
	      this.name = name;
	    }

	    /**
	     * Add a song to the playlist.
	     * 
	     * @param name the name of the song
	     */
	    public void addSong(String name) {
	      songs.add(name);
	    }

	    public String getName() {
	      return name;
	    }

	    /**
	     * Return the list of songs in the playlist.
	     */
	    public List<String> getSongs() {
	      return songs;
	    }
	  }

	  /**
	   * A composer of classical music.
	   */
	  private static class Composer {
	    private final String name;
	    private final List<Playlist> playlists = new ArrayList<Playlist>();

	    public Composer(String name) {
	      this.name = name;
	    }

	    /**
	     * Add a playlist to the composer.
	     * 
	     * @param playlist the playlist to add
	     */
	    public Playlist addPlaylist(Playlist playlist) {
	      playlists.add(playlist);
	      return playlist;
	    }

	    public String getName() {
	      return name;
	    }

	    /**
	     * Return the rockin' playlist for this composer.
	     */
	    public List<Playlist> getPlaylists() {
	      return playlists;
	    }
	  }
	
	///////////////////////////////////////
	//Cell Tree
	  private static class CustomTreeModel implements TreeViewModel {

		    private final List<Composer> composers;

		    /**
		     * This selection model is shared across all leaf nodes. A selection model
		     * can also be shared across all nodes in the tree, or each set of child
		     * nodes can have its own instance. This gives you flexibility to determine
		     * how nodes are selected.
		     */
		    private final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>();

		    public CustomTreeModel() {
		      // Create a database of information.
		      composers = new ArrayList<Composer>();

		      // Add compositions by Beethoven.
		      {
		        Composer beethoven = new Composer("Patient Info");
		        composers.add(beethoven);

		        Playlist concertos = beethoven.addPlaylist(new Playlist("Add Patient Info"));
		        concertos.addSong("Add");
		        concertos.addSong("Edit");
		        
		        
		        Playlist quartets = beethoven.addPlaylist(new Playlist("Browse"));
		        quartets.addSong("XML Translator");
		        quartets.addSong("JSON Translator");
		        
		      }
		      
		      
		      {
			        Composer beethoven = new Composer("Patient Health Record");
			        composers.add(beethoven);

			        Playlist concertos = beethoven.addPlaylist(new Playlist("sensory-profile"));
			        concertos.addSong("EKG");
			        concertos.addSong("Blood Pressure");
			        concertos.addSong("Pulse Oximeter");
			        concertos.addSong("Temperature");
			        
			        Playlist quartets = beethoven.addPlaylist(new Playlist("sensor-value"));
			        quartets.addSong("Single Value");
			        quartets.addSong("Double Value");
			        quartets.addSong("Multiple Value");

			        Playlist sonatas = beethoven.addPlaylist(new Playlist("actuator"));
			        sonatas.addSong("Communication Interval");
			        sonatas.addSong("Sensing Interval");

			        
			      }

		      
		      {
			        Composer beethoven = new Composer("Clinical Decision Making");
			        composers.add(beethoven);

			        Playlist concertos = beethoven.addPlaylist(new Playlist("conflict resolver"));
			        concertos.addSong("conflict detector");
			        concertos.addSong("conflict resolver");
			        concertos.addSong("log");
			        
			        
			        Playlist quartets = beethoven.addPlaylist(new Playlist("autonomic learner"));
			        quartets.addSong("present info");
			        quartets.addSong("previous observations");
			        quartets.addSong("log");

			        
			      }


		      // Add compositions by Brahms.
		      
		    }

		    /**
		     * Get the {@link NodeInfo} that provides the children of the specified
		     * value.
		     */
		    public <T> NodeInfo<?> getNodeInfo(T value) {
		      if (value == null) {
		        // LEVEL 0.
		        // We passed null as the root value. Return the composers.

		        // Create a data provider that contains the list of composers.
		        ListDataProvider<Composer> dataProvider = new ListDataProvider<AddPatient.Composer>(
		            composers);

		        // Create a cell to display a composer.
		        Cell<Composer> cell = new AbstractCell<Composer>() {
		          @Override
		          public void render(Context context, Composer value, SafeHtmlBuilder sb) {
		            if (value != null) {
		              sb.appendEscaped(value.getName());
		            }
		          }
		        };

		        // Return a node info that pairs the data provider and the cell.
		        return new DefaultNodeInfo<Composer>(dataProvider, cell);
		      } else if (value instanceof Composer) {
		        // LEVEL 1.
		        // We want the children of the composer. Return the playlists.
		        ListDataProvider<Playlist> dataProvider = new ListDataProvider<Playlist>(
		            ((Composer) value).getPlaylists());
		        Cell<Playlist> cell = new AbstractCell<Playlist>() {
		          @Override
		          public void render(Context context, Playlist value, SafeHtmlBuilder sb) {
		            if (value != null) {
		              sb.appendEscaped(value.getName());
		            }
		          }
		        };
		        return new DefaultNodeInfo<Playlist>(dataProvider, cell);
		      } else if (value instanceof Playlist) {
		        // LEVEL 2 - LEAF.
		        // We want the children of the playlist. Return the songs.
		        ListDataProvider<String> dataProvider = new ListDataProvider<String>(
		            ((Playlist) value).getSongs());

		        // Use the shared selection model.
		        return new DefaultNodeInfo<String>(dataProvider, new TextCell(),
		            selectionModel, null);
		      }

		      return null;
		    }

		    /**
		     * Check if the specified value represents a leaf node. Leaf nodes cannot be
		     * opened.
		     */
		    public boolean isLeaf(Object value) {
		      // The leaf nodes are the songs, which are Strings.
		      if (value instanceof String) {
		        return true;
		      }
		      return false;
		    }

		  }
	

	
	//////////
	
	
	
	
	
	
	
	
	
	
	public void onModuleLoad() {
		RootPanel rootPanel = RootPanel.get();
		
		AbsolutePanel absolutePanel = new AbsolutePanel();
		rootPanel.add(absolutePanel, 10, 10);
		absolutePanel.setSize("217px", "711px");
		
		

		TreeViewModel model = new CustomTreeModel();
		CellTree cellTree = new CellTree(model,null);
		cellTree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

		    // Open the first playlist by default.
		TreeNode rootNode = cellTree.getRootTreeNode();
		TreeNode firstPlaylist = rootNode.setChildOpen(0, true);
		firstPlaylist.setChildOpen(0, true);

		
		absolutePanel.add(cellTree, 37, 47);
		cellTree.setSize("128px", "607px");
		
		AbsolutePanel absolutePanel_1 = new AbsolutePanel();
		rootPanel.add(absolutePanel_1, 315, 55);
		absolutePanel_1.setSize("414px", "88px");
		
		Label lblPatientName = new Label("Patient Name:");
		absolutePanel_1.add(lblPatientName, 10, 29);
		
		Label lblInsuranceId = new Label("Insurance ID:");
		absolutePanel_1.add(lblInsuranceId, 10, 68);
		
		TextBox textBox = new TextBox();
		textBox.setText("Joo Hwa Lee");
		absolutePanel_1.add(textBox, 136, 29);
		textBox.setSize("141px", "15px");
		
		TextBox textBox_1 = new TextBox();
		textBox_1.setText("8401015763498");
		absolutePanel_1.add(textBox_1, 136, 61);
		textBox_1.setSize("141px", "15px");
		
		TabLayoutPanel tabLayoutPanel = new TabLayoutPanel(1.5, Unit.EM);
		
		
		
		//Normal Condition
		FlexTable flexTable = new FlexTable();
		tabLayoutPanel.add(flexTable, "Normal", false);
		flexTable.setSize("315px", "103px");
		
		Label lblHeartRate = new Label("Heart Rate");
		lblHeartRate.addStyleName("testrossi");
		flexTable.setWidget(0, 0, lblHeartRate);
		
				
		Label lblBloodPressure = new Label("Blood Pressure");
		lblBloodPressure.addStyleName("testrossi");
		flexTable.setWidget(0, 1, lblBloodPressure);
		
		Label lblTemperature = new Label("Temperature");
		lblTemperature.addStyleName("testrossi");
		flexTable.setWidget(0, 2, lblTemperature);
		
		
		Label lblHeartRateval = new Label("Every 30 min");
		flexTable.setWidget(1, 0, lblHeartRateval);
		
		Label lblBloodPressureval = new Label("Every 30 min");
		flexTable.setWidget(1, 1, lblBloodPressureval);
		
		Label lblTemperatureval = new Label("Every 30 min");
		flexTable.setWidget(1, 2, lblTemperatureval);
		
		
		
		
		//Normal Condition
				FlexTable flexTable1 = new FlexTable();
				tabLayoutPanel.add(flexTable1, "Prone", false);
				flexTable1.setSize("313px", "95px");
				
				Label lblHeartRate1 = new Label("Heart Rate");
				lblHeartRate1.addStyleName("testrossi");
				flexTable1.setWidget(0, 0, lblHeartRate1);
				
						
				Label lblBloodPressure1 = new Label("Blood Pressure");
				lblBloodPressure1.addStyleName("testrossi");
				flexTable1.setWidget(0, 1, lblBloodPressure1);
				
				Label lblTemperature1 = new Label("Temperature");
				lblTemperature1.addStyleName("testrossi");
				flexTable1.setWidget(0, 2, lblTemperature1);
				
				
				Label lblHeartRateval1 = new Label("Every 1 min");
				flexTable1.setWidget(1, 0, lblHeartRateval1);
				
				Label lblBloodPressureval1 = new Label("Every 1 min");
				flexTable1.setWidget(1, 1, lblBloodPressureval1);
				
				Label lblTemperatureval1 = new Label("Every 1 min");
				flexTable1.setWidget(1, 2, lblTemperatureval1);
				
		
				
				//Critical Condition
				FlexTable flexTable2 = new FlexTable();
				tabLayoutPanel.add(flexTable2, "Critical", false);
				flexTable2.setSize("313px", "95px");
				
				Label lblHeartRate2 = new Label("Heart Rate");
				lblHeartRate2.addStyleName("testrossi");
				flexTable2.setWidget(0, 0, lblHeartRate2);
				
						
				Label lblBloodPressure2 = new Label("Blood Pressure");
				lblBloodPressure2.addStyleName("testrossi");
				flexTable2.setWidget(0, 1, lblBloodPressure2);
				
				Label lblTemperature2 = new Label("Temperature");
				lblTemperature2.addStyleName("testrossi");
				flexTable2.setWidget(0, 2, lblTemperature2);
				
				
				Label lblHeartRateval2 = new Label("Every 5s");
				flexTable2.setWidget(1, 0, lblHeartRateval2);
				
				Label lblBloodPressureval2 = new Label("Every 5s");
				flexTable2.setWidget(1, 1, lblBloodPressureval2);
				
				Label lblTemperatureval2 = new Label("Every 5s ");
				flexTable2.setWidget(1, 2, lblTemperatureval2);
			
		
		
				
		
		rootPanel.add(tabLayoutPanel, 315, 355);
		tabLayoutPanel.setSize("316px", "121px");
		
		Label lblHealthcareSensorConfiguration = new Label("Healthcare Sensor Configuration");
		rootPanel.add(lblHealthcareSensorConfiguration, 315, 333);
		
		AbsolutePanel absolutePanel_2 = new AbsolutePanel();
		rootPanel.add(absolutePanel_2, 315, 165);
		absolutePanel_2.setSize("414px", "152px");
		
		Label lblDisease = new Label(" Disease:");
		absolutePanel_2.add(lblDisease, 10, 10);
		
		Label lblSymptoms = new Label("Symptoms");
		absolutePanel_2.add(lblSymptoms, 10, 40);
		
		Label lblPhysicianName = new Label("Physician Name:");
		absolutePanel_2.add(lblPhysicianName, 10, 73);
		
		TextBox textBox_2 = new TextBox();
		textBox_2.setText("Hypertension");
		absolutePanel_2.add(textBox_2, 137, 0);
		textBox_2.setSize("148px", "15px");
		
		TextBox textBox_3 = new TextBox();
		textBox_3.setText("High Blood Pressure");
		absolutePanel_2.add(textBox_3, 137, 40);
		textBox_3.setSize("148px", "15px");
		
		TextBox textBox_4 = new TextBox();
		textBox_4.setText("Dc. Seouk Geun Lee");
		absolutePanel_2.add(textBox_4, 137, 73);
		
		
	}
}
